home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / MiscKit1.7.1 / MiscKit / Headers / misckit / MiscParseTableFile.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-12  |  3.9 KB  |  103 lines

  1. //
  2. // MiscParseTableFile.h -- functions and categories to parse files of
  3. //            the format taken by *.addresses, PB.project, and others.
  4. //        Written by Don Yacktman Copyright (c) 1994 by Don Yacktman.
  5. //                Version 1.0.  All rights reserved.
  6. //
  7. //        This notice may not be removed from this source code.
  8. //
  9. //    This object is included in the MiscKit by permission from the author
  10. //    and its use is governed by the MiscKit license, found in the file
  11. //    "LICENSE.rtf" in the MiscKit distribution.  Please refer to that file
  12. //    for a list of all applicable permissions and restrictions.
  13. //    
  14.  
  15. #import <objc/objc.h>
  16. @class MiscString;
  17. @class MiscDictionary;
  18.  
  19. // We use a recursive descent parser to accomplish the parsing and
  20. // a recursive algorithm to write out the file contents.  The file
  21. // is represented at the top level with a "MiscDictionary" object.
  22. // The keys are all NXAtoms (unique strings) and the values are all
  23. // objects.  These objects can be MiscStrings, MiscLists, and
  24. // MiscDictionaries.  In the file, a MiscList is represented by a
  25. // comma separated list of strings, dictionaries, or lists surrounded
  26. // by parenthesis ().  A MiscDictionary is represented with a series
  27. // of key/value pairs (with the values again as strings, lists, and
  28. // dictionaries) surrounded by curly braces {}.  Look at a PB.project
  29. // or a *.addresses file for examples of legal files.  A good example is
  30. // /usr/template/user/Library/Addresses/Example.addresses/AddressBook.table
  31. // which contains examples of strings, lists, and dictionaries.  The
  32. // BNF grammar below might help, too, assuming I wrote it out right...
  33.  
  34. extern id MiscParseTableFile(MiscString *fileName);
  35. extern id MiscParseTableStream(NXStream *aStream);
  36.  
  37. // These functions produce a file/stream parseable by the above.
  38. // They won't work if the data structre contains objects other than
  39. // MiscList, MiscDictionary, and MiscString, unless the objects
  40. // implement the method:
  41. //        - writeASCIIToStream:(NXStream *)aStream;
  42. // Note that parsing will only return the listed object types, so
  43. // it is imperative that your implementation write out a properly
  44. // parseable text if you plan to read in the files using the
  45. // MiscParse...() routines listed above.
  46.  
  47. extern int MiscWriteTableFile(MiscString *fileName, MiscDictionary *tableRoot);
  48. extern int MiscWriteTableStream(NXStream *aStream, MiscDictionary *tableRoot);
  49.  
  50. /*
  51.  
  52.     Here is the BNF implemented by this code:  (more or less accurate)
  53.     Start parsing with the File non-terminal.  ":=" to define non-terminals
  54.     and <epsilon> is used to denote when a non-terminal can reduce to
  55.     nothing (ie, it is not required).
  56.  
  57.     Literals (terminals) are given in single quotes '' and use the
  58.     following:
  59.         []   "any one of what is inside"
  60.         *    "zero or more of what preceeds"
  61.         ()   used for grouping
  62.         -    "anything in between"  (0-9 means "0123456789", etc.)
  63.  
  64.     File := Dictionary
  65.  
  66.     Dictionary := Dictionary Line
  67.     Dictionary := Line
  68.  
  69.     Line := <epsilon>
  70.     Line := String '=' Association ';'    # The String is the hash key and is
  71.                                         # always uniqued by the parser.
  72.  
  73.     Association := '{' Dictionary '}'    # Keyed groups of objects
  74.     Association := '(' List ')'            # Groups of unkeyed objects
  75.     Association := '{' '}'                # These can be empty as well...
  76.     Association := '(' ')'
  77.     Association := String
  78.  
  79.     List := List ',' Association        # List is comma separated group
  80.     List := Association
  81.  
  82.     String := '"' Eliteral '"'            # two types of string:  quoted, non-q.
  83.     String := Literal
  84.  
  85.     Literal := Literal '[A-Za-z0-9]'    # what can be in a non-quoted string
  86.     Literal := '[A-Za-z0-9]'
  87.  
  88.     Eliteral := Eliteral ELchar            # what can be in a quoted string
  89.     Eliteral := ELchar                    # the main diff is allowing white-
  90.                                         # space and "\" quoted characters
  91.  
  92.     ELchar := '[Any char except '\' and '"']'
  93.     ELchar := '\' '\'
  94.     ELchar := '\' '"'
  95.     ELchar := '\' 't'
  96.     ELchar := '\' 'n'
  97.     ELchar := '\' 'r'
  98.     ELchar := '\' '0' 'x' '([0-9A-Fa-f])*'    # hex constant
  99.     ELchar := '\' '0' '[0-7]*'                    # octal constant
  100.     ELchar := '\' '[1-9]' '[0-9]*'                # decimal constant
  101.  
  102. */
  103.